package net.bwie.douyin.dwd.log1.Function;

import net.bwie.douyin.dwd.log1.bean.TikTokBean;

import org.apache.flink.api.common.functions.AggregateFunction;

/**
 * @ClassName：GiftAmountAggregator
 * @Author: ZddddQ  
 * @Date: 2025/5/28 14:12  
 * @Description: 必须描述类做什么事情, 实现什么功能 
 */
public class GiftAmountAggregator
        implements AggregateFunction<TikTokBean, Double, Double> {

    @Override
    public Double createAccumulator() {
        return 0.0;  // 初始累加器为0.0
    }

    @Override
    public Double add(TikTokBean bean, Double accumulator) {
        // 每条数据触发金额累加
        return accumulator + bean.getGiftValue().doubleValue();
    }

    @Override
    public Double getResult(Double accumulator) {
        // 直接返回最终累加结果
        return accumulator;
    }

    @Override
    public Double merge(Double a, Double b) {
        // 合并并行任务的结果（如会话窗口）
        return a + b;
    }
}
